package com.huangsm.cloud.config;

import feign.Contract;
import feign.Feign;
import feign.Logger;
import feign.auth.BasicAuthRequestInterceptor;
import org.springframework.cloud.openfeign.support.SpringMvcContract;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

/**
 * 自定义feign配置
 * @author huang
 * @PACKAGE_NAME com.huangsm.cloud.consumer.config
 * @PROJECT_NAME microservice-springcloud
 * @date 2019/1/7
 * @version V1.0
 */
public class FeignConfiguration1 {
    /**
     * feign本身的注解feign.Contract.Default()
     * SpringMvc注解
     * @return
     */
    @Bean
    public Contract feignContract(){
        return new SpringMvcContract();
    }

    /**
     * 服务之间的权限访问,服务提供者的密码和用户名为admin
     * @return
     */
    @Bean
    public BasicAuthRequestInterceptor basicAuthRequestInterceptor(){
        return new BasicAuthRequestInterceptor("hsm","h199655");
    }

    /**
     * 配置Feign的日志级别
     * @return
     */
    @Bean
    public Logger.Level feignLoggerLevel(){
        return Logger.Level.FULL;
    }

    /**
     * 禁用单一feignclient对hystrix的支持
     * @return
     */
    @Bean
    @Scope("prototype")
    public Feign.Builder feignBuilder(){
        return Feign.builder();
    }
}
